package com.steam.sys.controller;

import com.steam.basic.util.AjaxResult;
import com.steam.basic.util.PageList;
import com.steam.sys.domain.Systemdictionarytype;
import com.steam.sys.query.SystemdictionarytypeQuery;
import com.steam.sys.service.ISystemdictionarytypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "部门接口类", description = "部门接口类")
@RestController
@RequestMapping("/systemdictionarytype")
class SystemdictionarytypeController {

    @Autowired
    private ISystemdictionarytypeService systemdictionarytypeService;

    @ApiOperation(value = "查询单个")
    //根据id查询
    @GetMapping("/{id}")
    public Systemdictionarytype findOne(@PathVariable("id")Long id){
        return systemdictionarytypeService.loadById(id);
    }

    @ApiOperation(value = "查询全部")
    //查询全部
    @GetMapping
    public List<Systemdictionarytype> findAll(){
        return systemdictionarytypeService.loadAll();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id")Long id){
        try {
            systemdictionarytypeService.remove(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"删除失败!");
        }
    }

    @ApiOperation(value = "添加和修改")
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody Systemdictionarytype systemdictionarytype){
        try {
            if (systemdictionarytype.getId() == null){
                systemdictionarytypeService.save(systemdictionarytype);
            }else {
                systemdictionarytypeService.update(systemdictionarytype);
            }
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败!");
        }
    }

    @ApiOperation(value = "分页查询")
    @PostMapping
    public PageList<Systemdictionarytype> queryPage(@RequestBody SystemdictionarytypeQuery query){
        return systemdictionarytypeService.queryPage(query);
    }

    @ApiOperation(value = "批量删除")
    @PatchMapping
    public AjaxResult patchRemove(@RequestBody List<Long> ids){
        try {
            systemdictionarytypeService.patchRemove(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败!");
        }
    }

}
